﻿using System;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using OrderCms.DataAccess;
using OrderCms.DataOperation;
using OrderCms.Utilities;
using 订单分流.Api;

namespace 订单分流
{
	// Token: 0x02000002 RID: 2
	public partial class Main : Form
	{
		// Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
		public Main()
		{
			this.InitializeComponent();
		}

		// Token: 0x06000002 RID: 2 RVA: 0x00002068 File Offset: 0x00000268
		private void SetButtonStart()
		{
			Appconst.DlgSet.SetButtonEN(this.StartBtn, false);
			Appconst.DlgSet.SetButtonEN(this.button1, false);
			Appconst.DlgSet.SetButtonEN(this.button2, false);
			Appconst.DlgSet.SetButtonEN(this.StopBtn, true);
		}

		// Token: 0x06000003 RID: 3 RVA: 0x000020C0 File Offset: 0x000002C0
		private void SetButtonStop()
		{
			Appconst.DlgSet.SetButtonEN(this.StartBtn, true);
			Appconst.DlgSet.SetButtonEN(this.button1, true);
			Appconst.DlgSet.SetButtonEN(this.button2, true);
			Appconst.DlgSet.SetButtonEN(this.StopBtn, false);
		}

		// Token: 0x06000004 RID: 4 RVA: 0x00002118 File Offset: 0x00000318
		private void button1_Click(object sender, EventArgs e)
		{
			Appconst.threadNum = Convert.ToInt32(this.ThreadcountTBox.Text);
			Appconst.threadFlag = true;
			this.SetButtonStart();
			for (int i = 0; i < Appconst.threadNum; i++)
			{
				new Thread(new ThreadStart(this.test))
				{
					IsBackground = true
				}.Start();
			}
		}

		// Token: 0x06000005 RID: 5 RVA: 0x00002180 File Offset: 0x00000380
		private void StartBtn_Click(object sender, EventArgs e)
		{
			Appconst.threadFlag = true;
			Appconst.threadNum = Convert.ToInt32(this.ThreadcountTBox.Text);
			this.SetButtonStart();
			new Thread(new ThreadStart(this.GetNumStart))
			{
				IsBackground = true
			}.Start();
			new Thread(new ThreadStart(this.NewMainStart))
			{
				IsBackground = true
			}.Start();
		}

		// Token: 0x06000006 RID: 6 RVA: 0x000021F4 File Offset: 0x000003F4
		private void test1()
		{
			byte[] filesByte = File.ReadAllBytes(Path.GetDirectoryName(Application.ExecutablePath) + "//AddIns//SupController.dll");
			Assembly assembly = Assembly.Load(filesByte);
			Type type = assembly.GetType("SupController.SupHttp");
			object obj = Activator.CreateInstance(type);
			for (;;)
			{
				MethodInfo GetMoney = type.GetMethod("GetMoney");
				FieldInfo ID = type.GetField("ID");
				ID.SetValue(obj, "1222222");
				object sss = GetMoney.Invoke(obj, null);
				Appconst.ShowLog(sss.ToString());
				Thread.Sleep(2000);
			}
		}

		// Token: 0x06000007 RID: 7 RVA: 0x0000228C File Offset: 0x0000048C
		private void test()
		{
			int i = 0;
			this.SetButtonStart();
			while (i < 10000 && Appconst.threadFlag)
			{
				i++;
				Stopwatch stopwatch = new Stopwatch();
				stopwatch.Start();
				Order_List_Insert order_List = new Order_List_Insert();
				order_List.Order_TypeId = 1;
				order_List.RechargeIp = "127.0.0.1";
				order_List.MemberNumber = Guid.NewGuid().ToString();
				order_List.RechargeNumber = "13800138000";
				order_List.RechargeNum = 1;
				order_List.RechargeAmount = 20.0;
				order_List.User_MemberId = 1;
				order_List.Order_Insert();
				long 耗时 = stopwatch.ElapsedMilliseconds;
				Appconst.ShowLog(string.Concat(new object[]
				{
					order_List.OrderNumber,
					",",
					order_List.UserAmount.ToString("0.000000"),
					",",
					order_List.RetCode,
					",",
					order_List.RetMsg,
					" 耗时:",
					耗时,
					"\r\n"
				}));
			}
			this.SetButtonStop();
		}

		// Token: 0x06000008 RID: 8 RVA: 0x000023BC File Offset: 0x000005BC
		private void GetNumStart()
		{
			while (Appconst.threadFlag)
			{
				try
				{
					StringBuilder sql = new StringBuilder();
					sql.AppendLine("SELECT COUNT(*)");
					sql.AppendLine("FROM [dbo].[Order_List] WITH(NOLOCK)");
					sql.AppendLine("WHERE");
					sql.AppendLine("OrderStatus=0 or OrderStatus=3");
					Appconst.sendCount = DbHelper.GetSingle(CommandType.Text, sql.ToString(), new DbParameter[0]);
					Thread.Sleep(3000);
				}
				catch (Exception ex)
				{
					Main.log.Error("统计数据", ex);
					Thread.Sleep(5000);
				}
			}
		}

		// Token: 0x06000009 RID: 9 RVA: 0x00002468 File Offset: 0x00000668
		private void NewMainStart()
		{
			PayClass pc = new PayClass();
			Thread th = new Thread(new ThreadStart(pc.StartPay));
			th.Start();
			th.Join();
			this.SetButtonStop();
		}

		// Token: 0x0600000A RID: 10 RVA: 0x000024A4 File Offset: 0x000006A4
		private void MainStart()
		{
			while (Appconst.threadFlag)
			{
				try
				{
					DateTime LastUpTime = QuerySql.GetLastUpTime();
					Appconst.SoftthreadFlag = true;
					DataTable User_GroupDt = QuerySql.GetUser_GroupDt();
					this.Threads = new Thread[User_GroupDt.Rows.Count];
					for (int i = 0; i < User_GroupDt.Rows.Count; i++)
					{
						int User_GroupId = Convert.ToInt32(User_GroupDt.Rows[i]["ID"]);
						string OrderNumberStart = Convert.ToString(User_GroupDt.Rows[i]["OrderNumberStart"]);
						PayClassV2 Get = new PayClassV2();
						Get.sIndex = i;
						Get.User_GroupId = User_GroupId;
						Get.OrderNumberStart = OrderNumberStart;
						this.Threads[i] = new Thread(new ThreadStart(Get.StartPay));
						this.Threads[i].Start();
					}
					while (Appconst.threadFlag && Appconst.SoftthreadFlag)
					{
						DateTime NowTime = QuerySql.GetLastUpTime();
						bool flag = NowTime > LastUpTime;
						if (flag)
						{
							Appconst.ShowLog("发现有新的平台");
							Appconst.SoftthreadFlag = false;
						}
						else
						{
							DateTimeHelper.ThreadSleep(ref Appconst.threadFlag, 10000);
						}
					}
					for (int j = 0; j < this.Threads.Length; j++)
					{
						bool flag2 = this.Threads[j] != null;
						if (flag2)
						{
							this.Threads[j].Join();
						}
					}
				}
				catch (Exception ex)
				{
					Appconst.ShowLog("线程错误:" + ex.Message);
					DateTimeHelper.ThreadSleep(ref Appconst.threadFlag, 10000);
				}
			}
			this.SetButtonStop();
		}

		// Token: 0x0600000B RID: 11 RVA: 0x00002680 File Offset: 0x00000880
		private void MAIN_Load(object sender, EventArgs e)
		{
			ThreadPool.SetMaxThreads(50, 50);
			Appconst.showTipLabel = this.label6;
			Appconst.showLogText = this.textBox3;
		}

		// Token: 0x0600000C RID: 12 RVA: 0x000026A3 File Offset: 0x000008A3
		private void Form1_Load(object sender, EventArgs e)
		{
			Appconst.showLogText = this.textBox3;
			Appconst.showTipLabel = this.label6;
			this.SetButtonStop();
		}

		// Token: 0x0600000D RID: 13 RVA: 0x000026C3 File Offset: 0x000008C3
		private void Main_FormClosing(object sender, FormClosingEventArgs e)
		{
			Appconst.threadFlag = false;
		}

		// Token: 0x0600000E RID: 14 RVA: 0x000026CC File Offset: 0x000008CC
		private void StopBtn_Click(object sender, EventArgs e)
		{
			Appconst.threadFlag = false;
			Appconst.DlgSet.SetButtonEN(this.StopBtn, false);
		}

		// Token: 0x0600000F RID: 15 RVA: 0x000026E8 File Offset: 0x000008E8
		private void button2_Click(object sender, EventArgs e)
		{
			Appconst.threadFlag = true;
			Appconst.threadNum = Convert.ToInt32(this.ThreadcountTBox.Text);
			this.SetButtonStart();
			new Thread(new ThreadStart(this.GetNumStart))
			{
				IsBackground = true
			}.Start();
			new Thread(new ThreadStart(this.MainStart))
			{
				IsBackground = true
			}.Start();
		}

		// Token: 0x04000001 RID: 1
		public static LogHelper log = LogFactory.GetLogger(typeof(Main));

		// Token: 0x04000002 RID: 2
		private Thread[] Threads;
	}
}
